package com.lambkit.module.monitor;

import java.util.List;

import com.lambkit.Lambkit;
import com.lambkit.common.ResultKit;
import com.lambkit.common.util.DateTimeUtils;
import com.lambkit.web.controller.LambkitController;

public class MonitorServerController extends LambkitController {

	public void index() {
		renderText("welcome to monitor...");
	}
	
	public void alive() {
		renderJson(ResultKit.json(1, "monitor", null));
	}
	
	/**
	 * client定时来签到
	 */
	public void checkin() {
		if(isPOST()) {
			String token = getPara("token");
			String id = getPara("id");
			String name = getPara("name");
			MonitorObject mo = Lambkit.getCache().get(MonitorServer.CACHE_CLIENT_LIST, id);
			if(mo==null) {
				mo = new MonitorObject(id, name, token);
			} else {
				mo.setId(id);
				mo.setName(name);
				mo.setToken(token);
			}
			Lambkit.getCache().put(MonitorServer.CACHE_CLIENT_LIST, id, mo);
			Lambkit.getCache().put(MonitorServer.CACHE_CLIENT_CHECK_IN, id, DateTimeUtils.getCurrentTimeLong());
			renderJson(ResultKit.json(1, "checkin", null));
		} else {
			renderJson(ResultKit.json(0, "checkin", null));
		}
	}
}
